package com.javaspeak.designpatterns.go4.structural.bridge;

/**
 * This application has an abstract class called AbstractShapeBridge which wraps
 * ShapeBuilder so that calling the buildShape() method of AbstractShapeBridge
 * internally calls the buildShape() method of the ShapeBuilder.
 * <p>
 * This wrapping allows the implementation of ShapeBuilder, currently
 * TriangleBuilder, to be readily switched for another implementation such as
 * SquareBuilder.
 * <p>
 * The implementation of the ShapeBuilder is passed through the constructor of
 * AbstractBridge.
 * <p>
 * BridgeImpl extends AbstractBridge and adds its own method, drawShape()
 * to draw the shape.  Internally the drawShape() method makes a call to the
 * buildShape() method in AbstractShapeBridge.
 * <p>
 * This pattern is pretty similar to the Adapter pattern.  Notice some
 * differences though:
 * <ul>
 *    <li>Adapter is more about wrapping a third party API so it can be used
 *        by the application API.
 *    <li>Bridge is more about having the ability to slot in different
 *        implementations.
 *    <li>The Bridge has an abstract class that wraps the implementation which
 *        is itself extended to add extra functionality
 *        (e.g. ShapeBridgeImpl.drawShape())
 *    <li>The Bridge pattern in this example can be considered to be a
 *        combination of the Strategy and Template patterns.
 * </ul>
 *
 *
 * @author John Dickerson
 */
public class ApplicationBridge {

    /**
     * Calls drawShape() on the bridge implementation
     */
    public void drawShape(){

        ShapeBridgeImpl shapeBridge = new ShapeBridgeImpl();
        shapeBridge.drawShape();
    }

    /**
     * @param args
     */
    public static void main(String[] args) {

        ApplicationBridge application = new ApplicationBridge();
        application.drawShape();
    }
}
